package org.eclipse.stp.policy_builder.tcpmonitor.source.impl;

import java.util.ArrayList;

import org.eclipse.stp.policy_builder.model.BasicMessage;
import org.eclipse.stp.policy_builder.model.IMessage;

public class TCPManager {
	private volatile static TCPManager manager ;
	private ArrayList<IMessage> list = new ArrayList<IMessage>();
	private TCPManager(){
		
	}
	
	public static TCPManager getManager(){
		if(manager==null){
			synchronized(TCPManager.class){
				manager = new TCPManager();
				return manager;
			}
		}
		
		return manager;
	}
	
	public void setMessage(String msg){
		IMessage temp = new TCPMessage(msg);
		list.add(temp);
	}
	
	public synchronized void setMessage(byte[] msg){
		if(msg!=null){
			setMessage((new String(msg)).trim());
		}
	}
	
	public IMessage[] getMessages(){
		return list.toArray(new IMessage[list.size()]);
			
	}
	
	public synchronized void removeMessage(IMessage message){
		list.remove(message);
	}
}
